package edu.jamestang.yeb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.jamestang.yeb.entity.MenuRole;
import edu.jamestang.yeb.mapper.MenuRoleMapper;
import edu.jamestang.yeb.service.MenuRoleService;
import edu.jamestang.yeb.util.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author JamesTang
 * @date 2021/12/16 0:35
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {

    @Autowired
    private MenuRoleMapper menuRoleMapper;


    @Override
    @Transactional
    public Resp updateMenuRole(Integer rid, Integer[] mIds) {

        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid", rid));
        if(null == mIds || 0 == mIds.length){
            return Resp.success("Update success");
        }

        Integer result = menuRoleMapper.insertRecord(rid, mIds);

        if(result == mIds.length){
            return Resp.success("Update success");
        }

        return Resp.error("Update error");
    }
}
